package design.factory.impl;

import design.factory.ICacheAdapter;
import design.master.EGM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author: hero生仔
 */
public class EGMCacheAdapter implements ICacheAdapter {

    private Logger logger = LoggerFactory.getLogger(EGMCacheAdapter.class);
    private EGM egm = new EGM();

    @Override
    public String get(String key) {
        System.out.println("调用EGM的get方法，key为{}" + key);
        return egm.gain(key);
    }

    @Override
    public void set(String key, String val) {
        logger.info("调用EGM的set方法，key为{}，value为{}", key, val);
        egm.set(key, val);
    }

    @Override
    public void set(String key, String val, long timeout, TimeUnit timeUnit) {
        logger.info("调用EGM的setEx方法，key为{}，value为{}，timeout为{}，timeUnit为{}", key, val, timeout, timeUnit);
        egm.setEx(key, val, timeout, timeUnit);
    }

    @Override
    public void del(String key) {
        logger.info("调用EGM的del方法，key为{}", key);
        egm.delete(key);
    }
}
